package com.inhim.pjhim.dowloadfile.adapter.provider;

import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chaychan.adapter.BaseItemProvider;
import com.inhim.pjhim.R;
import com.inhim.pjhim.dowloadfile.adapter.DownloadListAdapter;
import com.inhim.pjhim.entity.DownloadListLable;
import com.inhim.pjhim.utils.ImageLoaderUtils;

/**
 * @author ChayChan
 * @description: 章节标题
 * @date 2018/3/22  14:48
 */

public class HaveDownloadProvider extends BaseItemProvider<DownloadListLable, BaseViewHolder> {

    private Context context;

    public HaveDownloadProvider(Context context) {
        this.context = context;
    }

    @Override
    public void convert(BaseViewHolder helper, final DownloadListLable data, int i) {
        if (data == null) {
            //如果没有，则直接跳过
            return;
        }
        try {
            //处理相关业务逻辑
            TextView tv_size = helper.getView(R.id.tv_size);
            TextView tv_name = helper.getView(R.id.tv_name);
            TextView tv_num = helper.getView(R.id.tv_num);
            ImageView imageview1 = helper.getView(R.id.imageview1);
            ConstraintLayout constran=helper.getView(R.id.constran);
            /*constran.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(context, HaveDownloadListActivity.class);
                    intent.putExtra("type",data.getType());
                    context.startActivity(intent);
                }
            });*/
            tv_name.setText(data.getTitle());
            tv_size.setText(data.getFilreSize());
            tv_num.setText(data.getNum());
            if("".equals(data.getCover())){
                if("2".equals(data.getType())){
                    imageview1.setImageResource(R.mipmap.video_background);
                }else{
                    imageview1.setImageResource(R.mipmap.listening_background);
                }
            }else{
                ImageLoaderUtils.setImage(data.getCover(), imageview1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public int viewType() {
        return DownloadListAdapter.HAVE_DOWNLOAD;
    }

    @Override
    public int layout() {
        return R.layout.item_have_download;
    }
}
